<?php
class Bib_AuthAdapter implements Zend_Auth_Adapter_Interface {
	
	/**
	 * Username
	 * @var string
	 */
	protected $_username;
	
	/**
	 * Password hashed using SHA1()
	 * @var string
	 */
	protected $_passwordHash;
	
    /**
     * Sets username and password for authentication
     *
     * @return void
     */
    public function __construct($username, $password)
    {
    	$this->_username = $username;
    	$this->_passwordHash = sha1($password);
    }

    /**
     * Performs an authentication attempt
     *
     * @throws Zend_Auth_Adapter_Exception If authentication cannot
     *                                     be performed
     * @return Zend_Auth_Result
     */
    public function authenticate()
    {
		$user = UserManager::getInstance()
					->authenticateUser($this->_username, $this->_passwordHash);
					
		if($user instanceof User) {
			$result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $user);

		} else {
			$result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE, null);
		}

    	return $result;
    }
} 
